﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TangoGames.Scene;
using Microsoft.Xna.Framework;
using incubation_xna3d.Scene;

namespace incubation_xna3d.Scene
{
    class EnemiesManager : GameComponent, IEnemiesManager
    {
        #region Fields

        /// <summary>
        /// Gerenciador da cena
        /// </summary>
        private ISceneManager sceneManager;

        /// <summary>
        /// Lista de inimigos
        /// </summary>
        List<IEnemie> enemiesList = new List<IEnemie>();

        #endregion

        #region Properties

        /// <summary>
        /// Lista de inimigos
        /// </summary>
        public List<IEnemie> EnemiesList { get { return enemiesList; } set { enemiesList = value; } }

        /// <summary>
        /// Gerenciador da cena corrente
        /// </summary>
        public ISceneManager SceneManager { get { return sceneManager; } set { sceneManager = value; } }

        #endregion

        #region Constructor
        
        /// <summary>
        /// Função construtora
        /// </summary>
        /// <param name="sceneManager">Gerenciador da cena</param>
        public EnemiesManager(Game game, ISceneManager sceneManager):base(game)
        {
            this.sceneManager = sceneManager;
            game.Components.Add(this);

            // Cria inimigos iniciais
            CreatesInitialEnemies();
        }


        #endregion

        #region Methods

        /// <summary>
        /// adiciona inimigo
        /// </summary>
        /// <param name="enemie"></param>
        public void AddEnemie(IEnemie enemie)
        {
            enemiesList.Add(enemie);
        }

        /// <summary>
        /// Cria inimigos iniciais
        /// </summary>
        public void CreatesInitialEnemies()
        {
            Enemie enemie = new Enemie (Game, sceneManager.Camera);
            Point ini = new Point(3, 3);
            Vector2 inireal = sceneManager.PathMap.ConvertPoint(ini);
            enemie.Position = new Vector3(inireal.X, enemie.Position.Y, inireal.Y);
            enemie.BoardPosition = ini;
            AddEnemie(enemie);
        }

        #endregion

        #region Update

        /// <summary>
        /// Update
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            Point source = enemiesList[0].BoardPosition;
            Point destination = sceneManager.CharactersList[0].BoardPosition;
            path = sceneManager.PathMap.FindPath (source, destination,false);

        }

        #endregion

        #region Draw
        #endregion

        //**************testes
        public bool teste = true;

        public List<Point> path;
        //*********************
    }
}
